package com.atguigu.gmall.product.api;

import com.atguigu.gmall.model.web.WebCategoryAllVo;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Semaphore;

/**
 * @author 钟涛
 * @version 1.0
 * @description: TODO
 * @date 2021/12/10 11:16
 */
@RequestMapping("/api/index")
@RestController
public class WebCategoryController {
    @Autowired
    private BaseCategory1Service category1Service;
//    private Semaphore semaphore = new Semaphore(6000);
    /**
     * 获取所有三级分类数据
     */
    @RequestMapping("/categorys")
    public List<WebCategoryAllVo> getCategoryAll() throws Exception {
//        List<WebCategoryAllVo> list = category1Service.getAllCategoryWithDistributeLock(null);
        List<WebCategoryAllVo> list = category1Service.getAllCategoryFromDB();
        return list;
    }

//    @RequestMapping("/hello")
//    public String hello(){
//        boolean b = semaphore.tryAcquire();
//        System.out.println("*****springboot*****");
//        if(b){
//            System.out.println("请求进来了");
//            return "请求得到了处理!";
//        }else{
//            return "请求未被处理";
//        }
//    }

//    @Scheduled(cron = "* * * * * * ?")
//    public void reflash(){
//        //销毁每秒剩余的信号量
//        semaphore.drainPermits();
//        //释放6000的信号量
//        semaphore.release(6000);
//    }
}
